<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<meta name="keywords" content="distributed" />
	<meta name="description" content="distributed" />
	<!-- 网页标签标题 -->
	<title>distributed</title>
	<link rel="shortcut icon" href="/img/docsite.ico"/>
	<link rel="stylesheet" href="/build/documentation.css" />
</head>
<body>
	<div id="root"><div class="documentation-page" data-reactroot=""><header class="header-container header-container-normal"><div class="header-body"><a href="/en-us/index.html"><img class="logo" src="/img/txlcn.png"/></a><div class="search search-normal"><span class="icon-search"></span></div><span class="language-switch language-switch-normal">中</span><div class="header-menu"><img class="header-menu-toggle" src="/img/system/menu_gray.png"/><ul><li class="menu-item menu-item-normal"><a href="/en-us/index.html" target="_self">Home</a></li><li class="menu-item menu-item-normal"><a href="https://bbs.txlcn.org/viewtopic.php?id=42" target="_self">News</a></li><li class="menu-item menu-item-normal"><a href="https://bbs.txlcn.org/" target="_self">Forum</a></li><li class="menu-item menu-item-normal"><a href="/en-us/docs/preface.html" target="_self">Docs</a></li><li class="menu-item menu-item-normal"><a href="https://github.com/codingapi/tx-lcn/releases" target="_blank">Download</a></li><li class="menu-item menu-item-normal"><a href="/en-us/sponsor/index.html" target="_self">Sponsor</a></li></ul></div></div></header><div class="bar"><div class="bar-body"><img src="/img/system/docs.png" class="front-img"/><span>Documents</span><img src="/img/system/docs.png" class="back-img"/></div></div><section class="content-section"><div class="sidemenu"><div class="sidemenu-toggle"><img src="https://img.alicdn.com/tfs/TB1E6apXHGYBuNjy0FoXXciBFXa-200-200.png"/></div><ul><li class="menu-item menu-item-level-1"><span>User Guide</span><ul><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/en-us/docs/preface.html" target="_self">Preface</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/en-us/docs/background.html" target="_self">Background</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/en-us/docs/start.html" target="_self">Quick Start</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/en-us/docs/dependencies.html" target="_self">Dependencies</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><span>Demos<img style="transform:rotate(-90deg)" class="menu-toggle" src="/img/system/arrow_down.png"/></span><ul><li class="menu-item menu-item-level-3"><a href="/en-us/docs/demo/env.html" target="_self">DTX Demo</a></li><li class="menu-item menu-item-level-3"><a href="/en-us/docs/demo/dubbo.html" target="_self">Dubbo of TC</a></li><li class="menu-item menu-item-level-3"><a href="/en-us/docs/demo/springcloud.html" target="_self">Springcloud of TC</a></li></ul></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><span>In-depth TXLCN<img style="transform:rotate(-90deg)" class="menu-toggle" src="/img/system/arrow_down.png"/></span><ul><li class="menu-item menu-item-level-3"><a href="/en-us/docs/principle/control.html" target="_self">Explain</a></li><li class="menu-item menu-item-level-3"><a href="/en-us/docs/principle/lcn.html" target="_self">LCN Transaction Mode</a></li><li class="menu-item menu-item-level-3"><a href="/en-us/docs/principle/tcc.html" target="_self">TCC Transaction Mode</a></li><li class="menu-item menu-item-level-3"><a href="/en-us/docs/principle/txc.html" target="_self">TXC Transaction Mode</a></li></ul></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><span>Settings<img style="transform:rotate(-90deg)" class="menu-toggle" src="/img/system/arrow_down.png"/></span><ul><li class="menu-item menu-item-level-3"><a href="/en-us/docs/setting/client.html" target="_self">TC Settigns</a></li><li class="menu-item menu-item-level-3"><a href="/en-us/docs/setting/manager.html" target="_self">TM Settings</a></li><li class="menu-item menu-item-level-3"><a href="/en-us/docs/setting/distributed.html" target="_self">LoadBalance and TM Cluster</a></li></ul></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><span>Extensions<img style="transform:rotate(-90deg)" class="menu-toggle" src="/img/system/arrow_down.png"/></span><ul><li class="menu-item menu-item-level-3"><a href="/en-us/docs/expansion/transaction.html" target="_self">Transaction Mode</a></li><li class="menu-item menu-item-level-3"><a href="/en-us/docs/expansion/message.html" target="_self">TXMSG&#x27;s Protocol</a></li><li class="menu-item menu-item-level-3"><a href="/en-us/docs/expansion/rpc.html" target="_self">TXMSG</a></li></ul></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/en-us/docs/communication.html" target="_self">Command of TXMSG</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/en-us/docs/manageradmin.html" target="_self">TM guide</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/en-us/docs/debug.html" target="_self">When troubles</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/en-us/docs/test.html" target="_self">Test report</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/en-us/docs/developer.html" target="_self">Developers</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/en-us/docs/fqa.html" target="_self">FQA</a></li></ul></li></ul></div><div class="doc-content markdown-body"><h1>负载与集群配置</h1>
<p>    负载集群分为业务模块与TxManager</p>
<ul>
<li>业务模块负载集群说明</li>
</ul>
<p>    模块的集群集群基于springcloud或dubbo机制，集群的方式都是围绕服务发现来完成的，关于模块的负载集群配置这里将不阐述，可参考dubbo与springcloud资料。</p>
<ul>
<li>TxManager集群说明</li>
</ul>
<p>    TxManager集群比较简单，只需要控制TxManager下的db资源相同(mysql 、redis)部署多份即可,注意TxManager负载均衡5.0版本与之前版本机制不同。</p>
<h2>TX-LCN 负载均衡介绍</h2>
<p>使用步骤：</p>
<ol>
<li>
<p>首选需要启动多个TxManager服务。</p>
</li>
<li>
<p>在客户端配置TxManager服务地址。</p>
</li>
</ol>
<pre><code>tx-lcn.client.manager-address=127.0.0.1:8070,127.0.0.1:8072
</code></pre>
<p>原理介绍：</p>
<p>当有事务请求客户端时事务发起端会随机选择一个可用TxManager作为事务控制方，然后告知其参与模块都与该模块通讯。</p>
<blockquote>
<p>目前TX-LCN的负载机制仅提供了随机机制。</p>
</blockquote>
<ul>
<li>关于tx-lcn.client.manager-address的注意事项：</li>
</ul>
<ol>
<li>
<p>客户端在配置上tx-lcn.client.manager-address地址后,启动时必须要全部可访问客户端才能正常启动。</p>
</li>
<li>
<p>当tx-lcn.client.manager-address中的服务存在不可用时，客户端会重试链接11次，超过次数以后将不在重试，重试链接的间隔时间为15秒，当所有的TxManager都不可访问则会导致所有的分布式事务请求都失败回滚。</p>
</li>
<li>
<p>当增加一个新的TxManager的集群模块时不需要添加到tx-lcn.client.manager-address下，TxManager也会广播到所有的TxManager端再通知所有链接中的TxClient端新的TxManager加入。</p>
</li>
</ol>
<h2>模块端负载集群注意事项</h2>
<p>    目前TX-LCN支持的事务种类有三种，其中LCN模式是会占用资源，详情见LCN模式原理。</p>
<p>若存在这样的请求链,A模块先调用了B模块的one方法，然后在调用了two方法，如下所示：</p>
<pre><code>A -&gt;B.one();
A -&gt;B.two();
</code></pre>
<p>假如one与two方法的业务都是在修改同一条数据,假如两个方法的id相同，伪代码如下:</p>
<pre><code>void one(id){
   execute =&gt; update demo set state = 1 where id = {id} ;
}

void two(id){
   execute =&gt; update demo set state = 2 where id = {id} ;
}

</code></pre>
<p>若B模块做了集群存在B1、B2两个模块。那么就可能出现A分别调用了B1 B2模块，如下:</p>
<pre><code>A -&gt;B1.one();
A -&gt;B2.two();
</code></pre>
<p>在这样的情况下业务方将在LCN下会因为资源占用而导致执行失败而回滚事务。为了支持这样的场景，框架提供了重写了rpc的负载模式。</p>
<p>控制在同一次事务下同一个被负载的模块被重复调用时将只会请求到第一次被选中的模块。</p>
<p>针对dubbo需要指定loadbalance为txlcn的负载方式，框架重写了dubbo的负载方式提供了对应dubbo的四种负载方式 :</p>
<pre><code>txlcn_random=com.codingapi.txlcn.tracing.dubbo.TxlcnRandomLoadBalance
txlcn_roundrobin=com.codingapi.txlcn.tracing.dubbo.TxlcnRoundRobinLoadBalance
txlcn_leastactive=com.codingapi.txlcn.tracing.dubbo.TxlcnLeastActiveLoadBalance
txlcn_consistenthash=com.codingapi.txlcn.tracing.dubbo.TxlcnConsistentHashLoadBalance

</code></pre>
<p>使用如下:</p>
<pre><code>   @Reference(version = &quot;${demo.service.version}&quot;,
            application = &quot;${dubbo.application.e}&quot;,
            retries = -1,
            registry = &quot;${dubbo.registry.address}&quot;,
            loadbalance = &quot;txlcn_random&quot;)
    private EDemoService eDemoService;

</code></pre>
<p>springcloud下需要在application的配置文件下增加:</p>
<pre><code>tx-lcn.springcloud.loadbalance.enabled=true
</code></pre>
</div></section><footer class="footer-container"><div class="footer-body"><img src="/img/txlcn.png"/><div class="cols-container"><div class="col col-12"><h3>Vision</h3><p>We will devote ourselves to creating a fast, efficient and concurrent distributed transaction solution.</p></div><div class="col col-6"><dl><dt>Navigation</dt><dd><a href="/zh-cn/docs/txlcn-arch.html" target="_self">TX-LCN Solution</a></dd><dd><a href="/zh-cn/docs/start.html" target="_self">Get Started</a></dd><dd><a href="/zh-cn/docs/txlcn-mod.html" target="_self">Develop Plan</a></dd><dd><a href="https://bbs.txlcn.org/viewforum.php?id=8" target="_self">Report Bug</a></dd></dl></div><div class="col col-6"><dl><dt>Friendship Link</dt><dd><a href="https://www.codingapi.com/" target="_blank">CodingApi</a></dd></dl></div></div><div class="copyright"><span>Copyright © 2018 CodingApi</span></div></div></footer></div></div>
	<script src="https://f.alicdn.com/react/15.4.1/react-with-addons.min.js"></script>
	<script src="https://f.alicdn.com/react/15.4.1/react-dom.min.js"></script>
	<script>
		window.rootPath = '';
  </script>
	<script src="/build/documentation.js"></script>
</body>
</html>